import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class FileoutputSteam001 {
    public static void main(String[] args) throws IOException {
        FileOutputStream f1 = new FileOutputStream("src//fos.txt");
        f1.write(97);
        f1.write("\r\n".getBytes());
       byte[] bytes = "abcdefg".getBytes(StandardCharsets.UTF_8);
       f1.write(bytes,1,3);
       //释放系统资源（必要）
        f1.close();

        //标准异常处理
        FileOutputStream f2 = new FileOutputStream("src//fos.txt");
      try {
          f2.write(97);
          f2.write("\r\n".getBytes());
          byte[] byte1 = "abcdefg".getBytes(StandardCharsets.UTF_8);
          f2.write(byte1, 1, 3);
      }catch (IOException e){
          e.printStackTrace();

      }finally {
          if (f2!=null){
          try {
              f2.close();
          }catch (IOException e) {
              e.printStackTrace();
          }
        }
      }
    //字节流读数据标准办法
        FileInputStream f3 = new FileInputStream("src//fos.txt");
        int by;
        while((by=f3.read())!=-1){
            System.out.print((char) by);
        }
        f3.close();







    }
}
